/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestionarClienteUI.java
 *
 * Created on 9/06/2009, 02:28:12 PM
 */

package CRM_UI;

import DAO.*;
import LogicaNegocio.Cliente;
import java.awt.Cursor;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author L¡z
 */
public class GestionarClienteUI extends javax.swing.JFrame
{
    Vector <Vector> clientesTabla;
    Vector <String> nombresColumnas;
    String idSeleccionado;
    RSC_UI objRscUI;
    Cursor handCursor = new Cursor(Cursor.HAND_CURSOR);
    Cursor defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);

    public GestionarClienteUI(RSC_UI objRscUIRSC_UI)
    {
        this.objRscUI = objRscUIRSC_UI;
        clientesTabla = new Vector <Vector>();
        idSeleccionado = " ";
        incializarColumnas();
        consultarClientes();
        initComponents();
        clientesTable.setModel(new DefaultTableModel (clientesTabla, nombresColumnas));
        setLocationRelativeTo(null);
    }

    public void actualizarTabla()
    {
        clientesTable.setModel(new DefaultTableModel (clientesTabla, nombresColumnas));
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        clientesTable = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        crearButton = new javax.swing.JButton();
        idLabel = new javax.swing.JLabel();
        nombreLabel = new javax.swing.JLabel();
        direccionLabel = new javax.swing.JLabel();
        ciudadLabel = new javax.swing.JLabel();
        identificadorTextField = new javax.swing.JTextField();
        nombreTextField = new javax.swing.JTextField();
        direccionTextField = new javax.swing.JTextField();
        ciudadTextField = new javax.swing.JTextField();
        telefonosLabel = new javax.swing.JLabel();
        webLabel = new javax.swing.JLabel();
        eventosLabel = new javax.swing.JLabel();
        fechaIngresoLabel = new javax.swing.JLabel();
        estadoLabel = new javax.swing.JLabel();
        telefono1TextField = new javax.swing.JTextField();
        webTextField = new javax.swing.JTextField();
        emailTextField = new javax.swing.JTextField();
        diaComboBox = new javax.swing.JComboBox();
        mesComboBox = new javax.swing.JComboBox();
        aNoComboBox = new javax.swing.JComboBox();
        estadoComboBox = new javax.swing.JComboBox();
        telefono2TextField = new javax.swing.JTextField();
        telefono3TextField = new javax.swing.JTextField();
        modificarButton = new javax.swing.JButton();
        eliminarButton = new javax.swing.JButton();
        casitaBoton = new javax.swing.JLabel();
        consultarButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Clientes"));

        /*
        clientesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        */
        clientesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        clientesTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clientesTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(clientesTable);

        jScrollPane2.setViewportView(jScrollPane1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(46, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 469, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Modificar"));

        crearButton.setText("crear");
        crearButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                crearButtonActionPerformed(evt);
            }
        });

        idLabel.setText("Identificador:");

        nombreLabel.setText("Nombre:");

        direccionLabel.setText("Direccion:");

        ciudadLabel.setText("Ciudad:");

        telefonosLabel.setText("Telefonos:");

        webLabel.setText("Web:");

        eventosLabel.setText("E-mail:");

        fechaIngresoLabel.setText("Fecha de Ingreso:");

        estadoLabel.setText("Estado:");

        diaComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));

        mesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "      -      ", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre" }));

        aNoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "    -     ", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009" }));

        estadoComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "       -         ", "Activo", "Retirado" }));

        modificarButton.setText("modificar");
        modificarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                modificarButtonActionPerformed(evt);
            }
        });

        eliminarButton.setText("eliminar");
        eliminarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminarButtonActionPerformed(evt);
            }
        });

        casitaBoton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/home.png"))); // NOI18N
        casitaBoton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                casitaBotonMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                casitaBotonMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                casitaBotonMouseExited(evt);
            }
        });

        consultarButton.setText("consultar");
        consultarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                consultarButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(idLabel)
                    .addComponent(nombreLabel)
                    .addComponent(direccionLabel)
                    .addComponent(telefonosLabel)
                    .addComponent(ciudadLabel)
                    .addComponent(webLabel)
                    .addComponent(eventosLabel)
                    .addComponent(fechaIngresoLabel)
                    .addComponent(estadoLabel))
                .addGap(14, 14, 14)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ciudadTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(direccionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(nombreTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(identificadorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(webTextField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(telefono1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(telefono2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(telefono3TextField, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(emailTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(diaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(mesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(aNoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(crearButton)
                                .addGap(18, 18, 18)
                                .addComponent(modificarButton)
                                .addGap(13, 13, 13)
                                .addComponent(eliminarButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(consultarButton)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(casitaBoton))
                    .addComponent(estadoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(idLabel)
                            .addComponent(identificadorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nombreTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(nombreLabel)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addContainerGap(110, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(direccionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(direccionLabel))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(ciudadTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(telefono1TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(telefono2TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(telefono3TextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(webTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addComponent(ciudadLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(telefonosLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(webLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(emailTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(diaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fechaIngresoLabel)
                            .addComponent(mesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(aNoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(eventosLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(estadoLabel)
                    .addComponent(estadoComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(crearButton)
                    .addComponent(eliminarButton)
                    .addComponent(modificarButton)
                    .addComponent(consultarButton))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(300, Short.MAX_VALUE)
                .addComponent(casitaBoton))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public void incializarColumnas()
    {
        nombresColumnas = new Vector <String> ();
        nombresColumnas.addElement("Identificador");
        nombresColumnas.addElement("Nombre");
        nombresColumnas.addElement("Dirección");
        nombresColumnas.addElement("Ciudad");
        nombresColumnas.addElement("Teléfonos");
        nombresColumnas.addElement("Web");
        nombresColumnas.addElement("E-mail");
        nombresColumnas.addElement("Fecha Ingreso");
        nombresColumnas.addElement("Estado");
    }

    public void consultarClientes()
    {
        clientesTabla.clear();
        DAOCliente daoCliente = new DAOCliente();
        DAOTelefono daoTelefono = new DAOTelefono();
        Vector <Cliente> losClientes = daoCliente.consultarClientes();
        Vector <String> telefonos = new Vector <String> ();

        for(int i=0; i<losClientes.size(); i++)
        {
            Vector <String> elCliente = new Vector <String>();
            elCliente.addElement(losClientes.elementAt(i).getIdCliente());
            elCliente.addElement(losClientes.elementAt(i).getNombreCliente());
            elCliente.addElement(losClientes.elementAt(i).getDireccionCliente());
            elCliente.addElement(losClientes.elementAt(i).getCiudadCliente());
            elCliente.addElement(losClientes.elementAt(i).getIdCliente()); // telefonos!
            elCliente.addElement(losClientes.elementAt(i).getPagWeb());
            elCliente.addElement(losClientes.elementAt(i).getEmail());
            elCliente.addElement(losClientes.elementAt(i).getFechaIngresoCliente());
            elCliente.addElement(losClientes.elementAt(i).getEstadoCliente());

            clientesTabla.addElement(elCliente);
        }
    }

    private void eliminarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminarButtonActionPerformed
        String fecha =diaComboBox.getSelectedItem().toString()+"-"+mesComboBox.getSelectedItem().toString()+"-"+aNoComboBox.getSelectedItem().toString();
        int option = JOptionPane.showConfirmDialog(null, "¿Esta seguro que desea borrar el cliente?", "Eliiminar Cliente" , JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

        if(option == 0)
        {
            //int fila = clientesTable.getSelectedRow();
            DAOCliente daoCliente = new DAOCliente();
            DAOTelefono daoTel= new DAOTelefono();
            Cliente cliente= new Cliente(identificadorTextField.getText(), nombreTextField.getText(), direccionTextField.getText(),
                                     ciudadTextField.getText(), webTextField.getText(), "23-09-02",
                                     estadoComboBox.getSelectedItem().toString(),emailTextField.getText());

            cliente.setTelefonoCliente(telefono1TextField.getText());
            cliente.setTelefonoCliente(telefono2TextField.getText());
            cliente.setTelefonoCliente(telefono3TextField.getText());

            Vector<String> v = cliente.getTelefonoCliente();
            for(int k = 0; k < v.size(); ++k)
            {
                System.out.println(v.elementAt(k));
                int j= daoTel.eliminarTelefono(v.elementAt(k), cliente.getIdCliente());
            }
            
            int i= daoCliente.eliminarCliente(identificadorTextField.getText());
            System.out.print("Se han borrado " + i + " Registro de la BD\n");
        }

        consultarClientes();
        actualizarTabla();
}//GEN-LAST:event_eliminarButtonActionPerformed

    private void crearButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_crearButtonActionPerformed
        String fecha="";

         if( !(diaComboBox.getSelectedIndex() == 0 ) && !(aNoComboBox.getSelectedIndex() == 0 ) && !(mesComboBox.getSelectedIndex() == 0 ))
         {
                if(mesComboBox.getSelectedIndex() <= 9)
                        {
                            fecha = diaComboBox.getSelectedItem().toString()+"-"+"0"+mesComboBox.getSelectedIndex()+"-"+aNoComboBox.getSelectedItem().toString();

                        }
                        else
                        {
                            fecha = diaComboBox.getSelectedItem().toString()+"-"+mesComboBox.getSelectedIndex()+"-"+aNoComboBox.getSelectedItem().toString();

                        }

                DAOCliente daoCliente= new DAOCliente();
                DAOTelefono daoTelefono= new DAOTelefono();
                Cliente cliente= new Cliente(identificadorTextField.getText(), nombreTextField.getText(), direccionTextField.getText(),
                                             ciudadTextField.getText(), webTextField.getText(), fecha,
                                             estadoComboBox.getSelectedItem().toString(),emailTextField.getText());

                cliente.setTelefonoCliente(telefono1TextField.getText());
                cliente.setTelefonoCliente(telefono2TextField.getText());
                cliente.setTelefonoCliente(telefono3TextField.getText());

                 int i=0;
                 int j=0;
                 int m=0;
                 int n=0;
                i=daoCliente.guardarCliente(cliente);
                Vector<String> v = cliente.getTelefonoCliente();
                for(int k = 0; k < v.size(); ++k)
                {
                    System.out.println(v.elementAt(k));
                    if(!v.elementAt(k).equals(""))
                    {
                        j= daoTelefono.guardarTelefono(v.elementAt(k), cliente.getIdCliente());
                    }

                }

                JOptionPane.showMessageDialog(null, "Se ha insertado "+i+" nuevo Cliente", "Cliente Nuevo", JOptionPane.INFORMATION_MESSAGE);
                System.out.print("Se han insertado " + i + " Registro a la BD\n");



         }
         else{
            JOptionPane.showMessageDialog(this, "Error en la fecha seleccionada", "Fecha errónea", JOptionPane.ERROR_MESSAGE);
         }
        

        consultarClientes();
        actualizarTabla();
}//GEN-LAST:event_crearButtonActionPerformed

    private void modificarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modificarButtonActionPerformed
        String fecha="";

         if( !(diaComboBox.getSelectedIndex() == 0 ) && !(aNoComboBox.getSelectedIndex() == 0 ) && !(mesComboBox.getSelectedIndex() == 0 ))
         {
                if(mesComboBox.getSelectedIndex() <= 9)
                        {
                            fecha = diaComboBox.getSelectedItem().toString()+"-"+"0"+mesComboBox.getSelectedIndex()+"-"+aNoComboBox.getSelectedItem().toString();
                            
                        }
                        else
                        {
                            fecha = diaComboBox.getSelectedItem().toString()+"-"+mesComboBox.getSelectedIndex()+"-"+aNoComboBox.getSelectedItem().toString();
                            
                        }

                DAOCliente daoCliente= new DAOCliente();
                DAOTelefono daoTelefono= new DAOTelefono();
                Cliente cliente= new Cliente(identificadorTextField.getText(), nombreTextField.getText(), direccionTextField.getText(),
                                             ciudadTextField.getText(), webTextField.getText(), fecha,
                                             estadoComboBox.getSelectedItem().toString(),emailTextField.getText());
                cliente.setTelefonoCliente(telefono1TextField.getText());
                cliente.setTelefonoCliente(telefono2TextField.getText());
                cliente.setTelefonoCliente(telefono3TextField.getText());

                int i= daoCliente.modificarNombreCliente(cliente);
                i= daoCliente.modificarNombreCliente(cliente);
                i= daoCliente.modificarDireccionCliente(cliente);
                i= daoCliente.modificarCiudadCliente(cliente);
                i= daoCliente.modificarPaginaWebCliente(cliente);
                i= daoCliente.modificarFechaIngresoCliente(cliente);
                i= daoCliente.modificarEstadoCliente(cliente);
                i= daoCliente.modificarEmailCliente(cliente);

                JOptionPane.showMessageDialog(null, "Se ha modificado "+i+" Cliente", "Cliente Modificado", JOptionPane.INFORMATION_MESSAGE);
                System.out.print("Se han insertado " + i + " Registro a la BD\n");

         }
        else{
            JOptionPane.showMessageDialog(this, "Error en la fecha seleccionada", "Fecha errónea", JOptionPane.ERROR_MESSAGE);
         }

        
        

        consultarClientes();
        actualizarTabla();
}//GEN-LAST:event_modificarButtonActionPerformed

    private void clientesTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clientesTableMouseClicked
       
        int fila = clientesTable.getSelectedRow();
        idSeleccionado = clientesTable.getValueAt(fila, 0).toString();
        identificadorTextField.setText(idSeleccionado);
        nombreTextField.setText(clientesTable.getValueAt(fila,1).toString());
        direccionTextField.setText(clientesTable.getValueAt(fila,2).toString());
        ciudadTextField.setText(clientesTable.getValueAt(fila,3).toString());
        webTextField.setText(clientesTable.getValueAt(fila,5).toString());
        emailTextField.setText(clientesTable.getValueAt(fila,6).toString());


}//GEN-LAST:event_clientesTableMouseClicked

    private void casitaBotonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_casitaBotonMouseClicked
        // TODO add your handling code here:
        objRscUI.setVisible(true);
        this.setVisible(false);  //destruirlo mejor
}//GEN-LAST:event_casitaBotonMouseClicked

    private void casitaBotonMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_casitaBotonMouseEntered
        // TODO add your handling code here:
        this.setCursor(handCursor);
    }//GEN-LAST:event_casitaBotonMouseEntered

    private void casitaBotonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_casitaBotonMouseExited
        // TODO add your handling code here:
        this.setCursor(defaultCursor);
    }//GEN-LAST:event_casitaBotonMouseExited

    private void consultarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarButtonActionPerformed
        // TODO add your handling code here:
        Vector <String> atributos = new Vector <String>();
        Vector <String> valores = new Vector <String>();
        String fecha = "";

        if( !identificadorTextField.getText().equals("") )
        {
            atributos.addElement("id_cliente");
            valores.addElement(identificadorTextField.getText());
        }

        if( !nombreTextField.getText().equals("") )
        {
            atributos.addElement("nombre_cliente");
            valores.addElement(nombreTextField.getText());
        }

        if( !direccionTextField.getText().equals("") )
        {
            atributos.addElement("direccion_cliente");
            valores.addElement(direccionTextField.getText());
        }

        if( !ciudadTextField.getText().equals("") )
        {
            atributos.addElement("ciudad_residencia");
            valores.addElement(ciudadTextField.getText());
        }

        if( !webTextField.getText().equals("") )
        {
            atributos.addElement("pagina_web_cliente");
            valores.addElement(webTextField.getText());
        }

        if( !emailTextField.getText().equals("") )
        {
            atributos.addElement("email_cliente");
            valores.addElement(emailTextField.getText());
        }

        if((diaComboBox.getSelectedIndex() != 0) && (mesComboBox.getSelectedIndex() != 0) && (aNoComboBox.getSelectedIndex() != 0) )
        {
            if( mesComboBox.getSelectedIndex() <= 9)
            {
                fecha=diaComboBox.getSelectedItem().toString()+"-"+"0"+
                        mesComboBox.getSelectedIndex()+
                        "-"+aNoComboBox.getSelectedItem().toString();
            }
            else
            {
                fecha=diaComboBox.getSelectedItem().toString()+"-"+
                        mesComboBox.getSelectedIndex()+
                        "-"+aNoComboBox.getSelectedItem().toString();
            }
        }

        if( estadoComboBox.getSelectedIndex() != 0)
        {
            atributos.addElement("estado_cliente");
            valores.addElement(estadoComboBox.getSelectedItem().toString());
        }

        DAOCliente objDaoCliente = new DAOCliente();
        clientesTabla.clear();
        clientesTabla = objDaoCliente.consultaParametrizada(fecha, atributos, valores);
        actualizarTabla();
    }//GEN-LAST:event_consultarButtonActionPerformed

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox aNoComboBox;
    private javax.swing.JLabel casitaBoton;
    private javax.swing.JLabel ciudadLabel;
    private javax.swing.JTextField ciudadTextField;
    private javax.swing.JTable clientesTable;
    private javax.swing.JButton consultarButton;
    private javax.swing.JButton crearButton;
    private javax.swing.JComboBox diaComboBox;
    private javax.swing.JLabel direccionLabel;
    private javax.swing.JTextField direccionTextField;
    private javax.swing.JButton eliminarButton;
    private javax.swing.JTextField emailTextField;
    private javax.swing.JComboBox estadoComboBox;
    private javax.swing.JLabel estadoLabel;
    private javax.swing.JLabel eventosLabel;
    private javax.swing.JLabel fechaIngresoLabel;
    private javax.swing.JLabel idLabel;
    private javax.swing.JTextField identificadorTextField;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JComboBox mesComboBox;
    private javax.swing.JButton modificarButton;
    private javax.swing.JLabel nombreLabel;
    private javax.swing.JTextField nombreTextField;
    private javax.swing.JTextField telefono1TextField;
    private javax.swing.JTextField telefono2TextField;
    private javax.swing.JTextField telefono3TextField;
    private javax.swing.JLabel telefonosLabel;
    private javax.swing.JLabel webLabel;
    private javax.swing.JTextField webTextField;
    // End of variables declaration//GEN-END:variables

}
